package com.gec.mall.service.impl;

import com.gec.mall.mapper.TbBrandMapper;
import com.gec.mall.pojo.TbBrand;
import com.gec.mall.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * @Author: li
 * @Date: 2023/1/7
 * @PACKAGE_NAME:com.gec.mall.service.impl
 * @Project_Name:mall-parent
 * @VERSION: 1.0.0
 */
@Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    private TbBrandMapper brandMapper;

    @Override
    public List<TbBrand> findAllBrand() {
        return brandMapper.selectByExample(null);
    }

    @Override
    public TbBrand findBrandById(Long id) {
        return brandMapper.selectByPrimaryKey(id);
    }

    @Override
    public void saveOrUpdateBrand(TbBrand brand) {
        if (ObjectUtils.isEmpty(brand.getId())){
            brandMapper.insert(brand);
        }else {
            brandMapper.updateByPrimaryKey(brand);
        }
    }

    @Override
    public void deleteBrandById(Long id) {
        brandMapper.deleteByPrimaryKey(id);
    }
}
